<%namespace name="include" file="/front/base/include.html" />
<%inherit file="/front/base/breadcrumbbase.html"/>

<%def name="breadcrumb()">
<li><a href="/coupons/list.html">优惠券</a><span class="divider">></span></li>
<li>列表</li>
</%def>


<%def name="center()">
<%!
import datetime
%>
<style>
.coupondetail p{
    margin: 0 0;
}
</style>
%for coupon in coupons.object_list:
<div class="row">
    %if request.session.peek_flash():
    <div class="alert alert-error">${request.session.pop_flash()[0]}</div>
    %endif
    <div class="page-header" style="margin:10px 0 15px;">
        <h3 class="no-margin">
            <a href="/coupons/detail/${coupon.id}.html">${coupon.name}</a>
            <small>本优惠券由"${coupon.businessuser.companyname}"提供</small>
        </h3>
    </div>
</div><!--coupons-->
<div class="row">  
    <ul class="thumbnails">
        <li class="span3">
            <a href="#s"><img src="${coupon.picture}" class="img-polaroid"/></a>
        </li>
        <li class="span6">
            <div class="coupondetail">
            ${h.entertobr(coupon.detail)|n}
            </div>
            <p class="no-margin"><span class="label label-info">还&nbsp;&nbsp;&nbsp;&nbsp;剩:</span> <span class="badge badge-success">${coupon.number-len(coupon.couponrandoms)}张</span> <span class="badge badge-warning">${coupon.leftdays}天</span></p>
            <p class="no-margin"><span class="label label-info">有效期:</span> <span class="badge badge-success">${h.date(coupon.startdate)}</span> - <span class="badge badge-success">${h.date(coupon.enddate)}</span></p>
            <p class="no-margin"><span class="label label-info">商&nbsp;&nbsp;&nbsp;&nbsp;家:</span>&nbsp;<code>${coupon.businessuser.companyname}</code><br/>
            <br/>
            <button type="button" class="btn btn-success" id="getcoupon${coupon.id}">领取优惠券</button>
        </li>
    </ul>
</div><!--product-->
%endfor

${include.pagination(coupons)}
</%def>

<%def name="script()">
<script type="text/javascript">
    $(document).ready(function(){
        $("button[id^='getcoupon']").click(function(){
            var id = $(this).attr('id').replace('getcoupon','');
            %if not h.is_user_login(request):
            if(confirm('您需要先登陆, 为您转到登陆页?'))
            {
                window.location = '/user/login.html?backurl=${request.path}';
            }
            %else:
            window.location = '/coupons/auth/get/' + id + '.html';
            %endif
        })
    })
</script>
</%def>
